home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5809 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: solon.com!not-for-mail
  2. From: gast@pc5772.hil.siemens.at (Gastkennung am pc5772)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,comp.os.ms-windows.programmer.misc
  4. Subject: Re: Text representation of a number...
  5. Date: 21 Feb 1996 08:56:18 -0600
  6. Organization: Siemens AG Austria
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4gfbqi$27r@solutions.solon.com>
  10. References: <4fjm7r$odb@solutions.solon.com> <4fu8ek$9lp@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Newsreader: TIN [version 1.2 PL2]
  13.  
  14. : Joel York (yorkjoe@elof.acc.iit.edu) wrote:
  15. : : Greetings.
  16. : : I'm in need of an algorithm to take an eight-byte integer (not supported
  17. : : as a native type in Windows 3.1), and print its ASCII representation
  18. : : to a file.  This number comes from a server that stores the number in
  19. : : big-endian format, but I could switch it if necessary.  If anyone
  20. : : knows such an algorithm, or has a pointer to one, it'd be much
  21. : : appreciated.
  22. i fear  you wont get around defining the operation "div 10"
  23. and "mod 10" on your longish integer type.  Once you have that,
  24. you can repeatedly  use  x mod 10 as the next decimal digit  and then 
  25. replace x by (x div 10) until x is zero.
  26.   this will yield the decimal representation in reverse order (least
  27. significant digit first), but stringreversal shouldn't be a problem.
  28.  
  29. remains the problem of div'ing(mod'ing) your number-representation.
  30. you'll have to build it using the / and %  of smaller integertypes. (not 
  31. really easy, but it's possible)  
  32.   have a look on how you divide big numbers by hand (on paper), and then 
  33. try to re-implement that algorithm.
  34. --
  35. gast@pc5772.hil.siemens.co.at (Andreas Leitgeb)
  36. /* Hereby i grant you my non-exclusive permission to share my opinions */
  37.